package Day2025_04_12;

import java.util.*;

class Pair {
    private int key;
    private int value;
    public Pair () {}
    public Pair (int key, int value) {
        this.key = key;
        this.value = value;
    }

    public int getKey() {
        return key;
    }

    public void setKey(int key) {
        this.key = key;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Pair pair = (Pair) o;
        return key == pair.key && value == pair.value;
    }

    @Override
    public int hashCode() {
        return Objects.hash(key, value);
    }
}

public class Demo06 {
    static int[] dx = {1, -1, 0, 0};
    static int[] dy = {0, 0, 1, -1};
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        Map<Pair, Integer> hash = new HashMap<>();
        Queue<Pair> q = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            if (i == 0) q.add(new Pair(a, b));
            hash.put(new Pair(a, b), c);
        }
        double ret = 0;
        while (!q.isEmpty()) {
            int size = q.size();
            for (int i = 0; i < size; i++) {
                Pair pair = q.poll();
                int x = pair.getKey(), y = pair.getValue();
                for (int j = 0; j < 4; j++) {
                    x += dx[i]; y += dy[i];
                    Pair pair1 = new Pair(x, y);
                    if (hash.containsKey(pair1)) {
                        int tmp = hash.get(pair);
                        if (tmp > hash.get(pair1)) {
                            hash.put(pair1, tmp - 1);
                        } else {

                        }
                    } else {
                    }
                }
            }
        }
    }
}
